

class Employee:
    def __init__(self,eid,name,did,salary):
        self.eid=eid # 员工编号
        self.name=name
        self.did=did  # 部门编号
        self.salary=salary

    def __repr__(self):
        return f'Employee(eid={self.eid},name={self.name},did={self.did},salary={self.salary})'

employees = [
    Employee(1001,'茹凤',9002,16000),
    Employee(1002,'韩耀祖',9001,19000),
    Employee(1003,'谭新宇',9003,15000),
    Employee(1004,'千琪',9004,22000),
    Employee(1005,'李欣桐',9001,4000),

]

# 求所有员工中最高薪资的员工信息
# 方式一： 直接遍历
# maxV = employees[0]
# for emp in employees:
#     if maxV.salary < emp.salary:
#         maxV = emp
# print(maxV)

# 方式二： 通过max函数
# def find_maxSalary(employees):
#     return max(employees,key=lambda emp: emp.salary)
# print(find_maxSalary(employees))

# 方式三： lambda表达式
def get_max(condition): # 定义高阶函数
    maxV = employees[0]
    for emp in employees:
        if condition(maxV) < condition(emp):
            maxV = emp
    return maxV

# print(get_max(lambda emp:emp.salary))


# 求所有员工的薪资综合
# 1. 定义回调函数
def condition1(emp):
    return emp.salary

def get_sum(condition):
    total = 0
    for emp in employees:
        total += condition(emp)
    return total

# print(get_sum(condition1))

# lambda表达式
# print(get_sum(lambda e:e.salary))